#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>

int main()
{
    pid_t pid = fork();
    if(pid==0)
    {
        //子进程
        int count = 5;
        while(count)
        {
            printf("i am child process,pid: %d ,ppid: %d ,count= %d \n ",getpid(),getppid(),count);
            count--;
           sleep(1);
        }
        
    }
    else{
        //父亲
        int status = 0;
        pid_t rid = waitpid(pid,&status,0);
        if(rid>0)
        {
            //捕捉到指定子进程
            if(WIFEXITED(status))
            {
                printf("wait success,rid: %d ,status: %d ,errno: %d  \n",rid,status,WEXITSTATUS(status));
            }
            else{
                printf("child error\n");
            }
        }
    }
}
